package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author tongatong
 * @name BaseTrademarkController
 * @description
 * @date 2021/9/8
 * @time 18:40
 */
@Api(tags = "品牌管理")
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {
    @Resource
    private BaseTrademarkService baseTrademarkService;

    /**
     * 分页获取品牌列表
     * @param page 当前页
     * @param limit 每页显示多少条数据
     * @return  当前页品牌列表
     */
    @ApiOperation("分页列表")
    @GetMapping("{page}/{limit}")
    public Result<IPage<BaseTrademark>> index(@PathVariable("page") Long page, @PathVariable("limit") Long limit) {
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, limit);
        IPage<BaseTrademark> baseTrademarkIPageList = baseTrademarkService.getPage(baseTrademarkPage);
        return Result.ok(baseTrademarkIPageList);
    }

    /**
     * 根据id获取品牌
     * @param id 品牌id
     * @return  找查找的品牌
     */
    ///admin/product/baseTrademark/get/{id}
    @ApiOperation("获取详情")
    @GetMapping("get/{id}")
    public Result<BaseTrademark> getBaseTrademarkById(@PathVariable("id") Long id) {
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    /**
     * 根据id删除品牌
     * @param id 品牌id
     * @return result返回值
     */
    ///admin/product/baseTrademark/remove/{id}
    @ApiOperation("逻辑删除某个品牌")
    @DeleteMapping("remove/{id}")
    public Result<Void> deleteBaseTrademarkById(@PathVariable("id") Long id) {
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    /**
     * 根据id修改品牌信息
     * @param baseTrademark 要修改的品牌
     * @return result信息
     */
    ///admin/product/baseTrademark/update
    @ApiOperation("修改品牌")
    @PutMapping("update")
    public Result<Void> updateBaseTrademarkById(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    ///admin/product/baseTrademark/save
    @ApiOperation("新增品牌")
    @PostMapping("save")
    public Result<Void> saveBaseTrademark(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    /**
     * 查询全部品牌
     * @return 品牌信息
     */
    @ApiOperation("查询所有品牌")
    @GetMapping("getTrademarkList")
    public Result<List<BaseTrademark>> getTrademarkList() {
        List<BaseTrademark> baseTrademarkList = baseTrademarkService.list();
        return Result.ok(baseTrademarkList);
    }

}
